package org.biodas.jdas.client.adapters.features;

import org.biodas.jdas.schema.features.*;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: ljgarcia
 * Date: 23-Feb-2011
 * Time: 11:54:29
 * To change this template use File | Settings | File Templates.
 */
public class DasGFFAdapter extends DASGFF {
    //Attributes
	//Typed elements
    GFFAdapter gff;
    //Simple jaxb elements

    /**
     * New DasGFF adapter
     */
    public DasGFFAdapter () {
        this.gff.init();
    }

    /**
     * New DasGFF adapter from a DASGFF
     */
    public DasGFFAdapter (DASGFF dasgff) {
        this.gff = new GFFAdapter(dasgff.getGFF());
    }

    /**
     * Returns the adapted GGF element.
      * @return
     */
    public GFFAdapter getGFF() {
        return this.gff;
    }

    /**
     * Sets the adapted GFF element.
     * @param gff
     */
    public void setGFF(GFFAdapter gff) {
        this.gff = gff;
    }

    /**
     * Auxiliary class that represents the GFF element within an adapted DASGFF.
     */
    public class GFFAdapter extends GFF {
        //Attributes
        private List<SEGMENT> segments;
        private List<ERRORSEGMENT> errorSegments;
        private List<UNKNOWNSEGMENT> unknownSegments;
        private List<UNKNOWNFEATURE> unknownFeatures;

        /**
         * New GFFAdapter.
         */
        public GFFAdapter () {
            init();
        }

        /**
         * New GFFAdapter from a GFF
          */
        public GFFAdapter (GFF gff) {
            this.segmentOrERRORSEGMENTOrUNKNOWNSEGMENT = gff.getSEGMENTOrERRORSEGMENTOrUNKNOWNSEGMENT();
            this.href = gff.getHref();
            this.version = gff.getVersion();
            this.total = gff.getTotal();
            init();
        }

        /**
         * Initiates segments, errors, unknown segments, and unknown features lists.
         */
        private void init() {
            this.segments = new ArrayList<SEGMENT>();
            this.errorSegments = new ArrayList<ERRORSEGMENT>();
            this.unknownSegments = new ArrayList<UNKNOWNSEGMENT>();
            this.unknownFeatures = new ArrayList<UNKNOWNFEATURE>();
            for (Object segment:this.segmentOrERRORSEGMENTOrUNKNOWNSEGMENT) {
                if (segment instanceof SEGMENT) {
                    this.segments.add((SEGMENT)segment);
                } else if (segment instanceof UNKNOWNSEGMENT) {
                    this.unknownSegments.add((UNKNOWNSEGMENT)segment);
                } else if (segment instanceof UNKNOWNFEATURE) {
                    this.unknownFeatures.add((UNKNOWNFEATURE)segment);
                } else if (segment instanceof ERRORSEGMENT) {
                    this.errorSegments.add((ERRORSEGMENT)segment);
                }
            }
            this.segmentOrERRORSEGMENTOrUNKNOWNSEGMENT = null;
        }

        /**
         * Returns a list of adapted segments.
         * @return
         */
        public List<SEGMENT> getSegments() {
            return this.segments;
        }

        /**
         * Returns a list of error segments.
         * @return
         */
        public List<ERRORSEGMENT> getErrorSegments() {
            return this.errorSegments;
        }

        /**
         * Returns a list of unknown segments.
         * @return
         */
        public List<UNKNOWNSEGMENT> getUnknownSegments() {
            return this.unknownSegments;
        }

        /**
         * Returns a list of unknown segments.
         * @return
         */
        public List<UNKNOWNFEATURE> getUnknownFeatures() {
            return this.unknownFeatures;
        }

        /**
         * This method has been deprecated and will return null, use getSegments, getErrorSegments, getUnknownSegments, or get UnknownFeatures instead.
         * @return
         */
        @Deprecated
        public List<Object> getSEGMENTOrERRORSEGMENTOrUNKNOWNSEGMENT() {
            if (segmentOrERRORSEGMENTOrUNKNOWNSEGMENT != null) {
                segmentOrERRORSEGMENTOrUNKNOWNSEGMENT = null;
            }
            return this.segmentOrERRORSEGMENTOrUNKNOWNSEGMENT;
        }
    }
}
